<?php
class App_Module_Admin_Component_Users_Tpl_List extends App_Module_Admin_Tpl_List
{
	protected $_showCells = array('title', 'name', 'group', 'icons');
	protected $_emptyListMessage = 'NO_USERS';

    public function GetList($page)
    {
        $icons = array(
        	array(
        	'add' => array(
        					'title' => 'ADD',
        					'url' => Mozg::Router('http')->Create('module=admin&ctrl=users&action=add')
        					),
        	)
        );

        $onPage = Mozg_Cfg::Get('admin/users')->GetPerPage();

        $paginator = new Mozg_Paginator($page, $onPage);
        $pattern = Mozg::Router('http')->Create('module=admin&ctrl=users&action=list&page=__page__');

        $objects = Mozg_Mapper::Get('Users')->GetList(array('groups' => Mozg::User()->GetAvailableGroups()), $paginator);
        $paginator->SetTotalCount(Mozg_Mapper::Get('Users')->GetTotalRows());

        $content = $this->CreateList($objects, $paginator, $pattern);

        return $this->GetTpl('Base')->LoadTemplate(Mozg_Lang::_('USERS'), $content, $icons);
    }

    protected function GetHeaderTitle()
    {
    	return Mozg_Lang::_('LOGIN');
    }

    protected function GetHeaderName()
    {
    	return Mozg_Lang::_('NAME');
    }

    protected function GetHeaderGroup()
    {
    	return Mozg_Lang::_('GROUP');
    }

	protected function GetCellTitle($obj)
	{
		return $obj->GetUserName();
	}

	protected function GetCellName($obj)
	{
		return $obj->GetFullName();
	}

	protected function GetCellGroup($obj)
	{
		return $obj->GetGroup()->GetTitle();
	}

	protected function GetCellIcons($obj)
	{
        $icons = array(
        	'edit' => array(
        					'title' => 'EDIT',
        					'url' => Mozg::Router('http')->Create('module=admin&ctrl=users&action=add&id=' .$obj->GetId())
        					),

        	'delete' => array(
        					'title' => 'DELETE_USER?',
        					'url' => Mozg::Router('http')->Create('module=admin&ctrl=users&action=del&id=' .$obj->GetId())
        					),

        );
		return $this->GetTpl('Icon')->GetIconSet($icons, 'list');
	}
}